package org.paradise.dms.web.action.login;

import javax.servlet.http.HttpSession;


import org.apache.struts2.ServletActionContext;
import org.paradise.dms.pojo.Student;
import org.paradise.dms.services.StudentReportService;
import org.paradise.dms.web.action.DMSBaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * 
 * Description:学生登录Action
 * 
 * Copyright (c) paraDise sTudio(DT). All Rights Reserved.
 * 
 * @version 1.0 Mar 4, 2009 10:59:16 PM 李双江（paradise.lsj@gmail.com）created
 */
@Service
@Scope("prototype")
public class StudentLoginAction extends DMSBaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1059381417074509200L;
	
	private String username;

	private String password;
	
	private String identitycardno;//身份证号，激活时用
	
	private String password1;//修改密码一
	
	private String password2;//修改密码二
	
	@Autowired
	StudentReportService reportSerivce;
	
	public String login() {
		Student student = reportSerivce.login(username, password);
		if (student != null) {
			HttpSession session = ServletActionContext.getRequest().getSession();
			session.setAttribute("studentno", student.getStudentno());
			session.setAttribute("studentPreAsignid", student.getStudentpreasignedid());
			return SUCCESS;// "success"
		}
		addFieldError("", "登录失败，请确认身份信息");
		return INPUT;
	}
	
	public void validate() {
		clearErrorsAndMessages();
	}
	
	
	public String active() {
		if(null == password1 || null == password2 || !password1.equals(password2)) {
			addFieldError("password1", "密码重置错误");
			return "active";
		}
		Student student = reportSerivce.activeStudent(identitycardno,password1);
		
		if (null !=  student) {
			HttpSession session = ServletActionContext.getRequest().getSession();
			session.setAttribute("studentno", student.getStudentno());
			session.setAttribute("studentPreAsignid", student.getStudentpreasignedid());
			return SUCCESS;// "success"
		}
		addFieldError("", "激活过程出错");
		return "active";
	}
	
	
	
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}



	public String getIdentitycardno() {
		return identitycardno;
	}



	public void setIdentitycardno(String identitycardno) {
		this.identitycardno = identitycardno;
	}



	public String getPassword1() {
		return password1;
	}



	public void setPassword1(String password1) {
		this.password1 = password1;
	}



	public String getPassword2() {
		return password2;
	}



	public void setPassword2(String password2) {
		this.password2 = password2;
	}



	public StudentReportService getReportSerivce() {
		return reportSerivce;
	}



	public void setReportSerivce(StudentReportService reportSerivce) {
		this.reportSerivce = reportSerivce;
	}
	
	
}
